package com.kongjs.application.convert;

import com.kongjs.application.enums.OperationType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Optional;

@Component
public class OperationTypeConverter implements Converter<String, OperationType> {
    @Override
    public OperationType convert(String source) {
        Optional<OperationType> optional = Arrays.stream(OperationType.values()).filter(operationType -> operationType.getValue().equals(source)).findFirst();
        return optional.orElse(null);
    }
}
